package typejump.commands;

import typejump.Settings;
import typejump.Swagger;
import typejump.TypeJump;
import typejump.engine.GameEngine;
import typejump.objects.Actor;

public class LongJump implements TextCommand {
	
	private double costPerBoost = Settings.getDouble("longjump.cost");

	@Override
	public boolean matches(String command) {
		return command.toLowerCase().matches("juu+mp");
	}

	@Override
	public void act(String command) {
		Actor player = TypeJump.getInst().getPlayer();
		int boost = command.length()-4;
		
		if (!player.isOnGround())
			return;
		
		Swagger meter = Swagger.getInst();
		if (!meter.hasSwag(costPerBoost))
			return;
		
		double expent = meter.expendSwag(costPerBoost*boost);
		
		double portion = (expent / costPerBoost);
		double factor = Math.log(portion+Math.E);
		
		double vel = factor * player.getJumpVelocity();
		
		player.vy(vel);

		GameEngine.addTextEffect(command.toUpperCase(), "jump");
	}

}
